package com.xzzz.irda.guardcat.server.metric.redis;

import lombok.Builder;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Redis 慢日志对象
 */
@Data
@Builder
public class SlowLog {
    /**
     * 命令ID
     */
    private long id;
    /**
     * 命令时间
     */
    private long timestamp;
    /**
     * 命令用时
     */
    private long duration;
    /**
     * 命令参数内容
     */
    private List<String> args;

    public static SlowLog from(Object object){
        List data = (List)object;
        List<byte[]> args = (List<byte[]>) data.get(3);
        SlowLog slowlog = SlowLog.builder()
                .id(Long.parseLong(data.get(0).toString()))
                .timestamp(Long.parseLong(data.get(1).toString()))
                .duration(Long.parseLong(data.get(2).toString()))
                .args(args.stream().map(e -> new String(e)).collect(Collectors.toList()))
                .build();
        return slowlog;
    }
}
